package org.kineticsproject.application.util;
import java.io.File;
import java.io.IOException;
import java.util.Iterator;

import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import org.kineticsproject.visualizations.kmlgenerator;

import data.DataPackage;
import data.Exercise;
import data.Person;
import data.Population;


public class GenerateKMLVisualization {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		DataPackage dataPackage = DataPackage.eINSTANCE;
		
		//Create new ResourceSet & Resource
		ResourceSet resourceSet = new ResourceSetImpl();
		
		// Register XML resource factory
		resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xmi", 
		new XMIResourceFactoryImpl());

		Resource resource = resourceSet.createResource(URI.createFileURI(new File("myPopulation.xmi").getAbsolutePath()));

		// register package in local resource registry
		resourceSet.getPackageRegistry().put(dataPackage.getNsURI(), dataPackage);
		// load resource 
		resource.load(null);
		
	
		Population population = (Population)resource.getContents().get(0);
		
		Person casey = population.getPeople().get(0);
		
		Exercise grandcanyon = casey.getExercises().get(0);
		
		kmlgenerator kmlgen = new kmlgenerator();
		
		kmlgen.process("kelso.kml", grandcanyon);


	}

}
